package Interface;

import Controle.Percurso;
import Controle.Resultado;
import Modelo.Cidade;
import Modelo.Esquina;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.UIManager;

/**
 *
 * @author Spanhol e da Silva
 */
public class Main extends javax.swing.JFrame {

	private File file;
	private int serialName = 0;

	public Main() {

		//Look and Feel
		javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
		String piru = UIManager.getSystemLookAndFeelClassName();
		try {
			UIManager.setLookAndFeel(piru);
		} catch (Exception e) {
			System.out.println("fu**u");
		}
		//Acaba Look and Feel

		initComponents();
		jpPercurso.setVisible(false);
		jpRestricoes.setVisible(false);
		jlSelecionado2.setVisible(false);
		jtfSelecionado2.setVisible(false);
		jsMovimentada.setVisible(false);
		jsMovimentada.setMajorTickSpacing(20);
		jsSemaforo.setVisible(false);
		jsSemaforo.setMajorTickSpacing(20);

	}

	public void showPropriedades() {
		if (jpDraw.getSelected2() != null) {
			jtfSelecionado2.setText(jpDraw.getSelected2().getNome());
		} else {
			jtfSelecionado2.setText("");
		}
		if (jpDraw.getSelected() != null) {
			jtfSelecionado.setText(jpDraw.getSelected().getNome());
			jtfPosicaoX.setText(Integer.toString(jpDraw.getSelected().getX()));
			jtfPosicaoY.setText(Integer.toString(jpDraw.getSelected().getY()));
			jcbSemaforo.setSelected(jpDraw.getSelected().isSemaforo());
			jcbInteresse.setSelected(jpDraw.getSelected().isInteresse());
		} else {
			jtfSelecionado.setText("");
			jtfPosicaoX.setText("");
			jtfPosicaoY.setText("");
			jcbSemaforo.setSelected(false);
			jcbInteresse.setSelected(false);
		}
	}

	public void setPropriedades() {
		if (jpDraw.getSelected() != null) {
			if (jtfPosicaoX.getText().compareTo("") != 0) {
				jpDraw.getSelected().setX(Integer.parseInt(jtfPosicaoX.getText()));
			}
			if (jtfPosicaoY.getText().compareTo("") != 0) {
				jpDraw.getSelected().setY(Integer.parseInt(jtfPosicaoY.getText()));
			}
			jpDraw.getSelected().setNome(jtfSelecionado.getText());
			jpDraw.getSelected().setSemaforo(jcbSemaforo.isSelected());
			jpDraw.getSelected().setInteresse(jcbInteresse.isSelected());
			jpDraw.paintComponent(jpDraw.getGraphics());
		}
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this
	 * method is always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jpPercurso = new javax.swing.JPanel();
        jcbAlgoritmo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jpRestricoes = new javax.swing.JPanel();
        jlRestricoes = new javax.swing.JLabel();
        jcbEvitarSemaforo = new javax.swing.JCheckBox();
        jcbEvitarMovimentada = new javax.swing.JCheckBox();
        jsSemaforo = new javax.swing.JSlider();
        jsMovimentada = new javax.swing.JSlider();
        jLabel10 = new javax.swing.JLabel();
        jcbSomenteInteresse = new javax.swing.JCheckBox();
        jbEditar = new javax.swing.JButton();
        jpPropriedades = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jbPercurso = new javax.swing.JButton();
        jcbMovimentada = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane = new javax.swing.JScrollPane();
        jpDraw = new Interface.Draw();
        jPanel1 = new javax.swing.JPanel();
        jtfSelecionado = new javax.swing.JTextField();
        jlSelecionado = new javax.swing.JLabel();
        jtfPosicaoY = new javax.swing.JTextField();
        jtfPosicaoX = new javax.swing.JTextField();
        jlY = new javax.swing.JLabel();
        jcbSemaforo = new javax.swing.JCheckBox();
        jlCoordenadas = new javax.swing.JLabel();
        jlX = new javax.swing.JLabel();
        jlSelecionado2 = new javax.swing.JLabel();
        jtfSelecionado2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jcbInteresse = new javax.swing.JCheckBox();
        jMenuBar2 = new javax.swing.JMenuBar();
        jmFile = new javax.swing.JMenu();
        jmNovo = new javax.swing.JMenuItem();
        jmSalvar = new javax.swing.JMenuItem();
        jmAbrirMapa = new javax.swing.JMenuItem();
        jmAbrirImagem = new javax.swing.JMenuItem();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(800, 600));

        jcbAlgoritmo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "A*", "A* com restrições", "Amplitude", "Amplitude com restrições", "Profundidade", "Profundidade com restrições", "Profundidade iterativa", "Bidirecional", "Dijkstra", "Satisfação de restrições" }));
        jcbAlgoritmo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbAlgoritmoItemStateChanged(evt);
            }
        });

        jLabel2.setText("Algoritmo:");

        jLabel3.setText("Botão esquerdo do mouse: origem");

        jLabel4.setText("Botão direito do mouse: destino");

        jlRestricoes.setText("Evitar:");

        jcbEvitarSemaforo.setText("Semaforos");
        jcbEvitarSemaforo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbEvitarSemaforoActionPerformed(evt);
            }
        });

        jcbEvitarMovimentada.setText("Ruas movimentadas");
        jcbEvitarMovimentada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbEvitarMovimentadaActionPerformed(evt);
            }
        });

        jsSemaforo.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
        jsSemaforo.setMajorTickSpacing(20);
        jsSemaforo.setPaintLabels(true);
        jsSemaforo.setPaintTicks(true);
        jsSemaforo.setValue(0);

        jsMovimentada.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
        jsMovimentada.setMajorTickSpacing(20);
        jsMovimentada.setPaintLabels(true);
        jsMovimentada.setPaintTicks(true);
        jsMovimentada.setValue(0);

        javax.swing.GroupLayout jpRestricoesLayout = new javax.swing.GroupLayout(jpRestricoes);
        jpRestricoes.setLayout(jpRestricoesLayout);
        jpRestricoesLayout.setHorizontalGroup(
            jpRestricoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpRestricoesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlRestricoes)
                .addGap(160, 160, 160))
            .addGroup(jpRestricoesLayout.createSequentialGroup()
                .addGroup(jpRestricoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpRestricoesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jsMovimentada, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpRestricoesLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jpRestricoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcbEvitarMovimentada)
                            .addComponent(jcbEvitarSemaforo)
                            .addComponent(jsSemaforo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jpRestricoesLayout.setVerticalGroup(
            jpRestricoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpRestricoesLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(jlRestricoes)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbEvitarSemaforo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jsSemaforo, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jcbEvitarMovimentada)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jsMovimentada, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel10.setText("Percurso:");

        jcbSomenteInteresse.setSelected(true);
        jcbSomenteInteresse.setText("Somente pontos de interesse");
        jcbSomenteInteresse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbSomenteInteresseActionPerformed(evt);
            }
        });

        jbEditar.setText("<< Editar Grafo");
        jbEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpPercursoLayout = new javax.swing.GroupLayout(jpPercurso);
        jpPercurso.setLayout(jpPercursoLayout);
        jpPercursoLayout.setHorizontalGroup(
            jpPercursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpPercursoLayout.createSequentialGroup()
                .addGroup(jpPercursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpRestricoes, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jpPercursoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10))
                    .addGroup(jpPercursoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jpPercursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpPercursoLayout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addGroup(jpPercursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jcbSomenteInteresse)
                                    .addComponent(jcbAlgoritmo, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jbEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18))
        );
        jpPercursoLayout.setVerticalGroup(
            jpPercursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPercursoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbSomenteInteresse)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbAlgoritmo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpRestricoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jbEditar)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jpPropriedades.setAlignmentX(0.0F);
        jpPropriedades.setAlignmentY(0.0F);

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Mão dupla");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jbPercurso.setText("Percursos  >>");
        jbPercurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPercursoActionPerformed(evt);
            }
        });

        jcbMovimentada.setText("Movimentada");
        jcbMovimentada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbMovimentadaActionPerformed(evt);
            }
        });

        jLabel1.setText("Proxima Rua:");

        javax.swing.GroupLayout jpPropriedadesLayout = new javax.swing.GroupLayout(jpPropriedades);
        jpPropriedades.setLayout(jpPropriedadesLayout);
        jpPropriedadesLayout.setHorizontalGroup(
            jpPropriedadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPropriedadesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPropriedadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbMovimentada)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel1)
                    .addComponent(jbPercurso, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpPropriedadesLayout.setVerticalGroup(
            jpPropriedadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPropriedadesLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbMovimentada)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox1)
                .addGap(37, 37, 37)
                .addComponent(jbPercurso)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jpDraw.setFocusCycleRoot(true);
        jpDraw.setPreferredSize(new java.awt.Dimension(500, 500));
        jpDraw.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jpDrawMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jpDrawMouseReleased(evt);
            }
        });
        jpDraw.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                jpDrawMouseDragged(evt);
            }
        });
        jpDraw.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jpDrawKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jpDrawLayout = new javax.swing.GroupLayout(jpDraw);
        jpDraw.setLayout(jpDrawLayout);
        jpDrawLayout.setHorizontalGroup(
            jpDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 773, Short.MAX_VALUE)
        );
        jpDrawLayout.setVerticalGroup(
            jpDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 681, Short.MAX_VALUE)
        );

        jScrollPane.setViewportView(jpDraw);

        jtfSelecionado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSelecionadoActionPerformed(evt);
            }
        });
        jtfSelecionado.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfSelecionadoFocusLost(evt);
            }
        });

        jlSelecionado.setText("Nome:   ");

        jtfPosicaoY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfPosicaoYActionPerformed(evt);
            }
        });
        jtfPosicaoY.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfPosicaoYFocusLost(evt);
            }
        });

        jtfPosicaoX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfPosicaoXActionPerformed(evt);
            }
        });
        jtfPosicaoX.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfPosicaoXFocusLost(evt);
            }
        });

        jlY.setText("y: ");

        jcbSemaforo.setText("Semaforo");
        jcbSemaforo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbSemaforoActionPerformed(evt);
            }
        });

        jlCoordenadas.setText("Coordenadas:");

        jlX.setText("x: ");

        jlSelecionado2.setText("Destino:");

        jtfSelecionado2.setEditable(false);

        jLabel8.setText("Informações:");

        jcbInteresse.setText("Ponto de interesse");
        jcbInteresse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbInteresseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlSelecionado)
                                    .addComponent(jlSelecionado2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtfSelecionado, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                                    .addComponent(jtfSelecionado2)))
                            .addComponent(jLabel8)
                            .addComponent(jlCoordenadas)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jcbSemaforo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jcbInteresse))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addComponent(jlX)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfPosicaoX, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(jlY)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfPosicaoY, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jSeparator1))
                .addGap(8, 8, 8))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jtfPosicaoX, jtfPosicaoY});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSelecionado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlSelecionado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlSelecionado2)
                    .addComponent(jtfSelecionado2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jlCoordenadas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlX)
                    .addComponent(jtfPosicaoX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlY)
                    .addComponent(jtfPosicaoY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbSemaforo)
                    .addComponent(jcbInteresse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jmFile.setText("File");

        jmNovo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jmNovo.setText("Novo");
        jmNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmNovoActionPerformed(evt);
            }
        });
        jmFile.add(jmNovo);

        jmSalvar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jmSalvar.setText("Salvar mapa...");
        jmSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmSalvarActionPerformed(evt);
            }
        });
        jmFile.add(jmSalvar);

        jmAbrirMapa.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        jmAbrirMapa.setText("Abrir mapa...");
        jmAbrirMapa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmAbrirMapaActionPerformed(evt);
            }
        });
        jmFile.add(jmAbrirMapa);

        jmAbrirImagem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jmAbrirImagem.setText("Abrir imagem...");
        jmAbrirImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmAbrirImagemActionPerformed(evt);
            }
        });
        jmFile.add(jmAbrirImagem);

        jMenuBar2.add(jmFile);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jpPropriedades, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpPercurso, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpPropriedades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpPercurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jScrollPane)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void jpDrawMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jpDrawMouseDragged
		if (jpDraw.isEditar()) {
			if (jpDraw.getSelected() != null) {
				Esquina e = new Esquina(evt.getPoint().x, evt.getPoint().y);
				jpDraw.move(e);
				showPropriedades();
			}
		}
	}//GEN-LAST:event_jpDrawMouseDragged

	private void jpDrawMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jpDrawMouseReleased
		if (evt.getButton() == MouseEvent.BUTTON1) {
			if (!jpDraw.isEditar()) {
				//retorna esquina proxima ao ponto clicado ou uma nova esquina se nao houver nenhuma proxima
				Esquina p = jpDraw.getCidade().getEsquinaProxima(evt.getPoint().x, evt.getPoint().y);
				//se a selecao nao mudou nao ha nada para fazer
				if (p == null) {
					return;
				}
				if (!jpDraw.isSomenteInteresse()) {
					//se a selecao mudou, seta selecao para o novo ponto
					jpDraw.setSelected(p);
				} else {
					if (p.isInteresse()) {
						jpDraw.setSelected(p);
					} else {
						return;
					}
				}
				//mostra propriedades da esquina selecionada
				showPropriedades();
				//se existem duas esquinas selecionadas sera calculado o menor caminho entre elas atraves do algoritmo selecionado
				if (jpDraw.getSelected2() != null && jpDraw.getSelected() != null) {
					if (jcbAlgoritmo.getSelectedItem().toString().equals("A*")) {
						jpDraw.setCaminho(Percurso.aEstrela(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade()));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("A* com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							mov = jsMovimentada.getValue();
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							sem = jsSemaforo.getValue();
						}
						jpDraw.setCaminho(Percurso.aEstrela(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Dijkstra")) {
						jpDraw.setCaminho(Percurso.dijkstra(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade()));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Bidirecional")) {
						Resultado r = Percurso.buscaBidirecional(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Amplitude")) {
						Resultado r = Percurso.buscaAmplitude(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Amplitude com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							if (jsMovimentada.getValue() > 0) {
								mov = 100;
							}
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							if (jsSemaforo.getValue() > 0) {
								sem = 100;
							}
						}
						Resultado r = Percurso.buscaAmplitude(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem);
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade")) {
						Resultado r = Percurso.buscaProfundidade(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							if (jsMovimentada.getValue() > 0) {
								mov = 100;
							}
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							if (jsSemaforo.getValue() > 0) {
								sem = 100;
							}
						}
						Resultado r = Percurso.buscaProfundidade(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem);
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade iterativa")) {
						Resultado r = Percurso.buscaProfundidadeIterativa(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Satisfação de restrições")) {
						Resultado r = Percurso.satisfacaoDeRestricoes(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (!jcbAlgoritmo.getSelectedItem().toString().equals("Selecione")) {
						if (jpDraw.getCaminho() == null) {
							jpDraw.setStatusText("Não foi possível encontrar um caminho");
						} else {
							jpDraw.setStatusText("");
						}
					} else {
						jpDraw.setStatusText("");
					}
				}
			}
		} else if (evt.getButton() == MouseEvent.BUTTON3) {
			//retorna esquina proxima ao ponto clicado ou uma nova esquina se nao houver nenhuma proxima
			Esquina p = jpDraw.getCidade().getEsquinaProxima(evt.getPoint().x, evt.getPoint().y);
			if (!jpDraw.isEditar() && p == null) {
				return;
			}
			//se a selecao mudou, seta selecao para o novo ponto
			if (!jpDraw.isSomenteInteresse() || p == null) {
				//se a selecao mudou, seta selecao para o novo ponto
				jpDraw.setSelected2(p);
			} else {
				if (p.isInteresse()) {
					jpDraw.setSelected2(p);
				} else {
					return;
				}
			}
			//mostra propriedades da esquina selecionada
			showPropriedades();
			//se existem duas esquinas selecionadas sera calculado o menor caminho entre elas atraves do algoritmo selecionado
			if (!jpDraw.isEditar()) {
				if (jpDraw.getSelected2() != null && jpDraw.getSelected() != null) {
					if (jcbAlgoritmo.getSelectedItem().toString().equals("A*")) {
						jpDraw.setCaminho(Percurso.aEstrela(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade()));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("A* com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							mov = jsMovimentada.getValue();
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							sem = jsSemaforo.getValue();
						}
						jpDraw.setCaminho(Percurso.aEstrela(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Dijkstra")) {
						jpDraw.setCaminho(Percurso.dijkstra(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade()));
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Bidirecional")) {
						Resultado r = Percurso.buscaBidirecional(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Amplitude")) {
						Resultado r = Percurso.buscaAmplitude(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Amplitude com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							if (jsMovimentada.getValue() > 0) {
								mov = 100;
							}
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							if (jsSemaforo.getValue() > 0) {
								sem = 100;
							}
						}
						Resultado r = Percurso.buscaAmplitude(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem);
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade")) {
						Resultado r = Percurso.buscaProfundidade(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade com restrições")) {
						int mov = 0;
						if (jcbEvitarMovimentada.isEnabled()) {
							if (jsMovimentada.getValue() > 0) {
								mov = 100;
							}
						}
						int sem = 0;
						if (jcbEvitarSemaforo.isEnabled()) {
							if (jsSemaforo.getValue() > 0) {
								sem = 100;
							}
						}
						Resultado r = Percurso.buscaProfundidade(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade(), mov, sem);
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade iterativa")) {
						Resultado r = Percurso.buscaProfundidadeIterativa(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (jcbAlgoritmo.getSelectedItem().toString().equals("Satisfação de restrições")) {
						Resultado r = Percurso.satisfacaoDeRestricoes(jpDraw.getSelected(), jpDraw.getSelected2(), jpDraw.getCidade());
						jpDraw.setCaminho(r.getCaminho());
						jpDraw.setVisitados(r.getVisitados());
					}
					if (!jcbAlgoritmo.getSelectedItem().toString().equals("Selecione")) {
						if (jpDraw.getCaminho() == null) {
							jpDraw.setStatusText("Não foi possível encontrar um caminho");
						} else {
							jpDraw.setStatusText("");
						}
					} else {
						jpDraw.setStatusText("");
					}
				}
			}
		}
		jpDraw.paintComponent(jpDraw.getGraphics());
	}//GEN-LAST:event_jpDrawMouseReleased

	private void jpDrawMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jpDrawMousePressed
		jpDraw.requestFocus();
		if (jpDraw.isEditar()) {
			setPropriedades();
			if (evt.getButton() == MouseEvent.BUTTON1) {
				if (jpDraw.isEditar()) {
					Esquina e = new Esquina(evt.getPoint().x, evt.getPoint().y);
					serialName++;
					e.setNome(Integer.toString(serialName));
					jpDraw.addNaLista(e);
					showPropriedades();
//					jpDraw.paintComponent(jpDraw.getGraphics());
				}
			}
			if (evt.getButton() == MouseEvent.BUTTON3) {
				Esquina p = jpDraw.cidade.getEsquinaProxima(evt.getPoint().x, evt.getPoint().y);
				jpDraw.setSelected(p);
				showPropriedades();
				jpDraw.paintComponent(jpDraw.getGraphics());
			}
		}
	}//GEN-LAST:event_jpDrawMousePressed

	private void jmAbrirImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmAbrirImagemActionPerformed
		JFileChooser j = new JFileChooser();
		int i = j.showOpenDialog(null);
		if (i == JFileChooser.APPROVE_OPTION) {
			file = j.getSelectedFile();
			try {
				BufferedImage bf = ImageIO.read(file);
				jpDraw.setBgimage(bf);
				jpDraw.redimenciona(bf.getWidth(), bf.getHeight());
			} catch (IOException ex) {
				Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
	}//GEN-LAST:event_jmAbrirImagemActionPerformed

	private void jtfPosicaoXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfPosicaoXActionPerformed
		setPropriedades();
	}//GEN-LAST:event_jtfPosicaoXActionPerformed

	private void jtfPosicaoYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfPosicaoYActionPerformed
		setPropriedades();
	}//GEN-LAST:event_jtfPosicaoYActionPerformed

	private void jtfSelecionadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSelecionadoActionPerformed
		setPropriedades();
	}//GEN-LAST:event_jtfSelecionadoActionPerformed

	private void jtfPosicaoXFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfPosicaoXFocusLost
		setPropriedades();
	}//GEN-LAST:event_jtfPosicaoXFocusLost

	private void jtfPosicaoYFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfPosicaoYFocusLost
		setPropriedades();
	}//GEN-LAST:event_jtfPosicaoYFocusLost

	private void jtfSelecionadoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfSelecionadoFocusLost
		setPropriedades();
	}//GEN-LAST:event_jtfSelecionadoFocusLost

	private void jmNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmNovoActionPerformed
		jpDraw.novo();
	}//GEN-LAST:event_jmNovoActionPerformed

	private void jpDrawKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jpDrawKeyPressed
		if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
			if (jpDraw.getSelected() != null) {
				jpDraw.getCidade().remove(jpDraw.getSelected());
				jpDraw.setSelected(null);
				jpDraw.paintComponent(jpDraw.getGraphics());
			}
		}
	}//GEN-LAST:event_jpDrawKeyPressed

	private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
		jpDraw.switchMaoDupla();
	}//GEN-LAST:event_jCheckBox1ActionPerformed

	private void jmSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmSalvarActionPerformed
		JFileChooser j = new JFileChooser();
		j.setApproveButtonText("Save");
		int i = j.showOpenDialog(null);
		if (i == JFileChooser.APPROVE_OPTION) {
			file = j.getSelectedFile();
			try {
				FileOutputStream fos = new FileOutputStream(file);
				ObjectOutputStream oos = new ObjectOutputStream(fos);
				oos.writeObject(jpDraw.getCidade());
			} catch (IOException ex) {
				Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
				System.out.println("Erro ao tentar salvar" + ex);
				System.exit(0);
			}
		}
	}//GEN-LAST:event_jmSalvarActionPerformed

	private void jmAbrirMapaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmAbrirMapaActionPerformed
		JFileChooser j = new JFileChooser();
		int i = j.showOpenDialog(null);
		if (i == JFileChooser.APPROVE_OPTION) {
			file = j.getSelectedFile();
			FileInputStream fis;
			ObjectInputStream ois;
			try {
				fis = new FileInputStream(file);
				ois = new ObjectInputStream(fis);
				try {
					jpDraw.setCidade((Cidade) ois.readObject());
				} catch (ClassNotFoundException ex) {
					Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
				}
				ois.close();
			} catch (IOException ex) {
				Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
				jpDraw.novo();
			}

		}
		jpDraw.paintComponent(jpDraw.getGraphics());
		jScrollPane.paintComponents(jScrollPane.getGraphics());
	}//GEN-LAST:event_jmAbrirMapaActionPerformed

	private void jbPercursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPercursoActionPerformed
		jpPropriedades.setVisible(false);
		jpPercurso.setVisible(true);
		jpDraw.setEditar(false);
		jlSelecionado.setText("Origem:");
		jtfSelecionado.setEditable(false);
		jlSelecionado2.setVisible(true);
		jtfSelecionado2.setVisible(true);
		jlCoordenadas.setVisible(false);
		jtfPosicaoX.setVisible(false);
		jtfPosicaoY.setVisible(false);
		jlX.setVisible(false);
		jlY.setVisible(false);
		jcbSemaforo.setVisible(false);
		jcbInteresse.setVisible(false);
		jpDraw.paintComponent(jpDraw.getGraphics());
	}//GEN-LAST:event_jbPercursoActionPerformed

	private void jbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarActionPerformed
		jpPercurso.setVisible(false);
		jpPropriedades.setVisible(true);
		jpDraw.setEditar(true);
		jpDraw.setSelected2(null);
		jpDraw.setSelected(null);
		jpDraw.setCaminho(null);
		jpDraw.paintComponent(jpDraw.getGraphics());
		jpDraw.setStatusText("");
		jlSelecionado.setText("Nome:");
		jtfSelecionado.setEditable(true);
		jlSelecionado2.setVisible(false);
		jtfSelecionado2.setVisible(false);
		jlCoordenadas.setVisible(true);
		jtfPosicaoX.setVisible(true);
		jtfPosicaoY.setVisible(true);
		jlX.setVisible(true);
		jlY.setVisible(true);
		jcbSemaforo.setVisible(true);
		jcbInteresse.setVisible(true);
		jpDraw.paintComponent(jpDraw.getGraphics());
		jpDraw.setVisitados(null);
	}//GEN-LAST:event_jbEditarActionPerformed

	private void jcbAlgoritmoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbAlgoritmoItemStateChanged
		if (jcbAlgoritmo.getSelectedItem().toString().equals("Amplitude com restrições")
				|| jcbAlgoritmo.getSelectedItem().toString().equals("Profundidade com restrições")
				|| jcbAlgoritmo.getSelectedItem().toString().equals("A* com restrições")) {
			jpRestricoes.setVisible(true);
		} else {
			jpRestricoes.setVisible(false);
		}
	}//GEN-LAST:event_jcbAlgoritmoItemStateChanged

	private void jcbSemaforoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbSemaforoActionPerformed
		setPropriedades();
	}//GEN-LAST:event_jcbSemaforoActionPerformed

	private void jcbMovimentadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbMovimentadaActionPerformed
		jpDraw.switchMovimentada();
	}//GEN-LAST:event_jcbMovimentadaActionPerformed

	private void jcbEvitarMovimentadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbEvitarMovimentadaActionPerformed
		if (jcbEvitarMovimentada.isSelected()) {
			jsMovimentada.setVisible(true);
		} else {
			jsMovimentada.setVisible(false);
			jsMovimentada.setValue(0);
		}
	}//GEN-LAST:event_jcbEvitarMovimentadaActionPerformed

	private void jcbEvitarSemaforoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbEvitarSemaforoActionPerformed
		if (jcbEvitarSemaforo.isSelected()) {
			jsSemaforo.setVisible(true);
		} else {
			jsSemaforo.setVisible(false);
			jsSemaforo.setValue(0);
		}
	}//GEN-LAST:event_jcbEvitarSemaforoActionPerformed

	private void jcbInteresseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbInteresseActionPerformed
		setPropriedades();
	}//GEN-LAST:event_jcbInteresseActionPerformed

	private void jcbSomenteInteresseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbSomenteInteresseActionPerformed
		jpDraw.setSomenteInteresse(jcbSomenteInteresse.isSelected());
		jpDraw.paintComponent(jpDraw.getGraphics());
	}//GEN-LAST:event_jcbSomenteInteresseActionPerformed
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {

		/*
		 * Create and display the form
		 */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new Main().setVisible(true);
			}
		});
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbPercurso;
    private javax.swing.JComboBox jcbAlgoritmo;
    private javax.swing.JCheckBox jcbEvitarMovimentada;
    private javax.swing.JCheckBox jcbEvitarSemaforo;
    private javax.swing.JCheckBox jcbInteresse;
    private javax.swing.JCheckBox jcbMovimentada;
    private javax.swing.JCheckBox jcbSemaforo;
    private javax.swing.JCheckBox jcbSomenteInteresse;
    private javax.swing.JLabel jlCoordenadas;
    private javax.swing.JLabel jlRestricoes;
    private javax.swing.JLabel jlSelecionado;
    private javax.swing.JLabel jlSelecionado2;
    private javax.swing.JLabel jlX;
    private javax.swing.JLabel jlY;
    private javax.swing.JMenuItem jmAbrirImagem;
    private javax.swing.JMenuItem jmAbrirMapa;
    private javax.swing.JMenu jmFile;
    private javax.swing.JMenuItem jmNovo;
    private javax.swing.JMenuItem jmSalvar;
    private Interface.Draw jpDraw;
    private javax.swing.JPanel jpPercurso;
    private javax.swing.JPanel jpPropriedades;
    private javax.swing.JPanel jpRestricoes;
    private javax.swing.JSlider jsMovimentada;
    private javax.swing.JSlider jsSemaforo;
    private javax.swing.JTextField jtfPosicaoX;
    private javax.swing.JTextField jtfPosicaoY;
    private javax.swing.JTextField jtfSelecionado;
    private javax.swing.JTextField jtfSelecionado2;
    // End of variables declaration//GEN-END:variables
}
